package mini.expr.lists;
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;

import mini.Env;
import mini.expr.Element;
import mini.expr.Expr;


public class Sequence extends Expr {
    
    private List<Element> elements = new ArrayList<Element>();
    
    /**
     * Stores expressions until they are evaluated.
     */
    private List<Expr> exprs = new ArrayList<Expr>();
    
    public Sequence() {
    }
    
    public Sequence(Expr e) {
        exprs.add(e);
    }
    
    public void add(Expr e) {
        exprs.add(0, e);
    }
    
    public List<Element> getElements() {
        return elements;
    }
    
    public int numElements() {
        return elements.size();
    }
    
    @Override
    public Element eval(List<Env> listOfEnvs, LinkedList var) {
    	
        for (Expr expr : exprs) {
            //just store the element in the list.
            elements.add(expr.eval(listOfEnvs, var));
        }
        
        exprs.clear();
        
        return null;
    }
    
    public void addToFront(Element element) {
        elements.add(0, element);
    }

    public Sequence clone() {
        Sequence newSeq = new Sequence();
        List<Element> newElements = new ArrayList<Element>();
        
        newSeq.elements = newElements;
        
        for(Element element : this.elements) {
            newElements.add(element.clone());
        }
        
        return newSeq;
    }
}
